import 'package:flutter/material.dart';
import 'package:haitao_app/haitao.dart';
import 'package:haitao_app/home.dart';
import 'package:haitao_app/hours.dart';
import 'tag_navigator.dart';
import 'package:flutter/cupertino.dart';

class Index extends StatefulWidget{

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return IndexWidget();
  }

}

class IndexWidget extends State<Index>{

  int currentIndex=0;
  Map<String,GlobalKey<NavigatorState>> globalkeys={
      NavigatorName.index:GlobalKey<NavigatorState>(),
      NavigatorName.haitao:GlobalKey<NavigatorState>(),
      NavigatorName.hours:GlobalKey<NavigatorState>(),
  };
  String tab=NavigatorName.index;
  var tabs=[NavigatorName.index,NavigatorName.haitao,NavigatorName.hours];

  IndexedStack _body;

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    _body=IndexedStack(
      children: <Widget>[
        Home(),
        Haitao(),
        Hours(),
      ],
      index: currentIndex,
    );
    return MaterialApp(
      home: Scaffold(
        body: _body,
        bottomNavigationBar: CupertinoTabBar(
          items: [
            BottomNavigationBarItem(
                icon: Icon(Icons.home),
                title: Text("首页")
            ),
            BottomNavigationBarItem(
                icon:  Icon(Icons.flight_takeoff),
                title: Text("海淘")
            ),
            BottomNavigationBarItem(
                icon:  Icon(Icons.access_time),
                title: Text("小时风云榜")
            ),
          ],
          currentIndex: currentIndex,
          onTap: (index){
            setCurrentIndex(index);
          },
        ),
      ),
    );
  }

  void setCurrentIndex(int index){
    setState(() {
      currentIndex=index;
      tab=tabs[index];
    });
    print(tab);
  }


}

